Skip to content

Conversation

@MananTank
Copy link
Member

@MananTank MananTank commented Dec 12, 2025


PR-Codex overview

This PR focuses on enhancing error handling in the billing-related actions by checking for specific error structures in the JSON response and returning a more informative error message.

Detailed summary

  • Added a check for the presence of error and message in the JSON response.
  • Ensured that json.error.message is a string before returning it.
  • Returned a structured error object containing the error message and a status of "error" if the checks pass.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • Bug Fixes
    • Improved billing error handling so API-provided error messages are surfaced to users (replaces generic fallback errors), giving clearer feedback when checkout or billing operations fail.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
thirdweb-www Ready Ready Preview Comment Dec 12, 2025 6:04pm
4 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
docs-v2 Skipped Skipped Dec 12, 2025 6:04pm
nebula Skipped Skipped Dec 12, 2025 6:04pm
thirdweb_playground Skipped Skipped Dec 12, 2025 6:04pm
wallet-ui Skipped Skipped Dec 12, 2025 6:04pm

@vercel vercel bot temporarily deployed to Preview – docs-v2 December 12, 2025 17:12 Inactive
@vercel vercel bot temporarily deployed to Preview – wallet-ui December 12, 2025 17:12 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground December 12, 2025 17:12 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula December 12, 2025 17:12 Inactive
@linear
Copy link

linear bot commented Dec 12, 2025

@changeset-bot
Copy link

changeset-bot bot commented Dec 12, 2025

⚠️ No Changeset found

Latest commit: 2bb6a4f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

Both billing functions now parse API JSON responses for an error object and, if error.message is a string, return that message as an early error result before checking json.result.

Changes

Cohort / File(s) Summary
Error Handling Enhancement
apps/dashboard/src/@/actions/billing.ts, apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
After parsing API JSON, added a pre-check: if json.error?.message is a string, return an error with that message immediately (early return) prior to existing json.result validation; no public signature changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Both files contain the same conditional addition and early-return pattern.
  • Check that the API consistently supplies error.message as a string in all relevant responses.
  • Confirm callers handle the returned error shape uniformly (status "error" + message).

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The PR description lacks required template sections like 'Notes for the reviewer' and 'How to test', though it includes PR-Codex overview documenting the changes made. Add 'Notes for the reviewer' section to highlight important details and complete 'How to test' section with testing instructions.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the issue (MNY-332) and summarizes the main change: improving error message handling in the checkout flow.
Linked Issues check ✅ Passed The changes directly implement the objective from MNY-332 by capturing and returning backend error messages instead of generic failures.
Out of Scope Changes check ✅ Passed Both modified files contain only error handling improvements scoped to the billing checkout flow, directly addressing the linked issue.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch mny-332

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 24c7484 and 2bb6a4f.

📒 Files selected for processing (2)
  • apps/dashboard/src/@/actions/billing.ts (1 hunks)
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.

Comment @coderabbitai help to get the list of available commands and usage tips.

@MananTank MananTank marked this pull request as ready for review December 12, 2025 17:12
@MananTank MananTank requested review from a team as code owners December 12, 2025 17:12
@github-actions github-actions bot added the Dashboard Involves changes to the Dashboard. label Dec 12, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (1)

51-95: New json.error.message handling can be unreachable (and can throw) — parse error payload for non-2xx + add guards.
Right now any HTTP 4xx/5xx returns in Line 51-75, so the new extraction (Line 79-88) won’t run for the reported 403 case in the issue. Also, ("message" in json.error) can throw if json.error is null or not an object.

Suggested patch (keeps existing status-specific messaging as fallback):

   const res = await fetch(
     `${NEXT_PUBLIC_THIRDWEB_API_HOST}/v1/teams/${options.teamSlug}/checkout/create-link`,
     {
@@
   );
   if (!res.ok) {
-    const text = await res.text();
-    console.error("Failed to create checkout link", text, res.status);
+    const text = await res.text();
+    console.error("Failed to create checkout link", text, res.status);
+
+    // Try to surface API-provided error message (e.g. { error: { message, statusCode } })
+    try {
+      const json: unknown = JSON.parse(text);
+      if (
+        json &&
+        typeof json === "object" &&
+        "error" in json &&
+        (json as any).error &&
+        typeof (json as any).error === "object" &&
+        "message" in (json as any).error &&
+        typeof (json as any).error.message === "string"
+      ) {
+        return { error: (json as any).error.message, status: "error" } as const;
+      }
+    } catch {
+      // ignore non-JSON bodies
+    }
+
     switch (res.status) {
       case 402: {
         return {
@@
     }
   }
 
-  const json = await res.json();
+  const json: unknown = await res.json();
 
   if (
-    "error" in json &&
-    "message" in json.error &&
-    typeof json.error.message === "string"
+    json &&
+    typeof json === "object" &&
+    "error" in json &&
+    (json as any).error &&
+    typeof (json as any).error === "object" &&
+    "message" in (json as any).error &&
+    typeof (json as any).error.message === "string"
   ) {
     return {
-      error: json.error.message,
+      error: (json as any).error.message,
       status: "error",
     } as const;
   }
 
-  if (!json.result) {
+  if (!json || typeof json !== "object" || !("result" in json) || !(json as any).result) {
     return {
       error: "An unknown error occurred, please try again later.",
       status: "error",
     } as const;
   }
apps/dashboard/src/@/actions/billing.ts (1)

79-129: Same as dashboard billing util: error-message extraction won’t help for 4xx/5xx + current guard can throw.
If the backend returns { error: { message } } alongside an HTTP 403/4xx, the current logic returns in Line 79-109 and never reaches Line 113-122; plus ("message" in json.error) is not safe without checking json.error is a non-null object.

I’d apply the same res.text() -> JSON.parse -> error.message extraction in the !res.ok block, and tighten the unknown JSON guards in the res.ok block (mirroring the patch suggested in apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts).

🧹 Nitpick comments (1)
apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (1)

7-15: Add an explicit return type for getBillingCheckoutUrl (per TS guidelines).
This will also make the new error payload path easier to consume safely.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ff8f413 and 24c7484.

📒 Files selected for processing (2)
  • apps/dashboard/src/@/actions/billing.ts (1 hunks)
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each TypeScript file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes in TypeScript
Avoid any and unknown in TypeScript unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.) in TypeScript

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity and testability
Re-use shared types from @/types or local types.ts barrel exports
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics whenever possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic in TypeScript files; avoid restating TypeScript types and signatures in prose

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
apps/{dashboard,playground-web}/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

apps/{dashboard,playground-web}/src/**/*.{ts,tsx}: Import UI component primitives from @/components/ui/* (Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground
Use Tailwind CSS only – no inline styles or CSS modules in dashboard and playground
Use cn() from @/lib/utils for conditional Tailwind class merging
Use design system tokens for styling (backgrounds: bg-card, borders: border-border, muted text: text-muted-foreground)
Expose className prop on root element for component overrides

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
apps/dashboard/src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

apps/dashboard/src/**/*.{ts,tsx}: Use NavLink for internal navigation with automatic active states in dashboard
Start server component files with import "server-only"; in Next.js
Read cookies/headers with next/headers in server components
Access server-only environment variables in server components
Perform heavy data fetching in server components
Implement redirect logic with redirect() from next/navigation in server components
Begin client component files with 'use client'; directive in Next.js
Handle interactive UI with React hooks (useState, useEffect, React Query, wallet hooks) in client components
Access browser APIs (localStorage, window, IntersectionObserver) in client components
Support fast transitions with prefetched data in client components
Always call getAuthToken() to retrieve JWT from cookies on server side
Use Authorization: Bearer header for API calls – never embed tokens in URLs
Return typed results (Project[], User[]) from server-side data fetches – avoid any
Wrap client-side API calls in React Query (@tanstack/react-query)
Use descriptive, stable queryKeys in React Query for cache hits
Configure staleTime/cacheTime in React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never import posthog-js in server components – only use analytics client-side

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
apps/dashboard/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/dashboard.mdc)

apps/dashboard/**/*.{ts,tsx}: Always import from the central UI library under @/components/ui/* for reusable core UI components like Button, Input, Select, Tabs, Card, Sidebar, Separator, Badge
Use NavLink from @/components/ui/NavLink for internal navigation to ensure active states are handled automatically
For notices and skeletons, rely on AnnouncementBanner, GenericLoadingPage, and EmptyStateCard components
Import icons from lucide-react or the project-specific …/icons exports; never embed raw SVG
Keep components pure; fetch data outside using server components or hooks and pass it down via props
Use Tailwind CSS as the styling system; avoid inline styles or CSS modules
Merge class names with cn from @/lib/utils to keep conditional logic readable
Stick to design tokens: use bg-card, border-border, text-muted-foreground and other Tailwind variables instead of hard-coded colors
Use spacing utilities (px-*, py-*, gap-*) instead of custom margins
Follow mobile-first responsive design with Tailwind helpers (max-sm, md, lg, xl)
Never hard-code colors; always use Tailwind variables
Combine class names via cn, and expose className prop if useful in components
Use React Query (@tanstack/react-query) for all client-side data fetching with typed hooks

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (AGENTS.md)

Biome governs formatting and linting; its rules live in biome.json. Run pnpm fix & pnpm lint before committing, ensure there are no linting errors

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
apps/{dashboard,playground}/**/*.{tsx,ts}

📄 CodeRabbit inference engine (AGENTS.md)

apps/{dashboard,playground}/**/*.{tsx,ts}: Import UI primitives from @/components/ui/_ (Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in Dashboard and Playground apps
Use NavLink for internal navigation so active states are handled automatically
Use Tailwind CSS for styling – no inline styles or CSS modules
Merge class names with cn() from @/lib/utils to keep conditional logic readable
Stick to design tokens for styling: backgrounds (bg-card), borders (border-border), muted text (text-muted-foreground), etc.
Server Components: Read cookies/headers with next/headers, access server-only environment variables or secrets, perform heavy data fetching, implement redirect logic with redirect() from next/navigation, and start files with import 'server-only'; to prevent client bundling
Client Components: Begin files with 'use client'; before imports, handle interactive UI relying on React hooks (useState, useEffect, React Query, wallet hooks), access browser APIs (localStorage, window, IntersectionObserver, etc.), and support fast transitions with client-side data prefetching
For client-side data fetching: Wrap calls in React Query (@tanstack/react-query), use descriptive and stable queryKeys for cache hits, configure staleTime / cacheTime based on freshness requirements (default ≥ 60 s), and keep tokens secret by calling internal API routes or server actions

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
apps/{dashboard,playground}/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

apps/{dashboard,playground}/**/*.{ts,tsx}: For server-side data fetching: Always call getAuthToken() to retrieve the JWT from cookies and inject the token as an Authorization: Bearer header – never embed it in the URL. Return typed results (Project[], User[], …) – avoid any
Never import posthog-js in server components; analytics reporting is client-side only

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (AGENTS.md)

Lazy-import optional features; avoid top-level side-effects

Files:

  • apps/dashboard/src/@/actions/billing.ts
  • apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Size
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)

@github-actions
Copy link
Contributor

github-actions bot commented Dec 12, 2025

size-limit report 📦

Path Size
@thirdweb-dev/nexus (esm) 105.66 KB (0%)
@thirdweb-dev/nexus (cjs) 319.47 KB (0%)

@codecov
Copy link

codecov bot commented Dec 12, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 54.64%. Comparing base (e281ed1) to head (2bb6a4f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8550   +/-   ##
=======================================
  Coverage   54.64%   54.64%           
=======================================
  Files         921      921           
  Lines       61181    61181           
  Branches     4151     4151           
=======================================
  Hits        33434    33434           
  Misses      27645    27645           
  Partials      102      102           
Flag Coverage Δ
packages 54.64% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@graphite-app
Copy link
Contributor

graphite-app bot commented Dec 12, 2025

Merge activity

<!--

## title your PR with this format: "[SDK/Dashboard/Portal] Feature/Fix: Concise title for the changes"

If you did not copy the branch name from Linear, paste the issue tag here (format is TEAM-0000):

## Notes for the reviewer

Anything important to call out? Be sure to also clarify these in your comments.

## How to test

Unit tests, playground, etc.

-->

<!-- start pr-codex -->

---

## PR-Codex overview
This PR enhances error handling in the `billing.ts` files by checking for a specific error structure in the JSON response. If the error is present and formatted correctly, it returns a detailed error message instead of a generic one.

### Detailed summary
- Added error handling for JSON responses in `apps/dashboard/src/@/actions/billing.ts`:
  - Checks if `error` and `message` exist in the response.
  - Validates that `json.error.message` is a string.
  - Returns a structured error object with the message and status.

- Similar changes were made in `apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts`.

> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`

<!-- end pr-codex -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

## Bug Fixes
* Improved error message handling for billing operations to display API-provided error messages to users instead of generic fallback errors, enabling clearer feedback when checkout transactions encounter issues.

<sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
@vercel vercel bot temporarily deployed to Preview – wallet-ui December 12, 2025 17:57 Inactive
@vercel vercel bot temporarily deployed to Preview – thirdweb_playground December 12, 2025 17:57 Inactive
@vercel vercel bot temporarily deployed to Preview – nebula December 12, 2025 17:57 Inactive
@vercel vercel bot temporarily deployed to Preview – docs-v2 December 12, 2025 17:57 Inactive
@graphite-app graphite-app bot merged commit 2bb6a4f into main Dec 12, 2025
22 checks passed
@graphite-app graphite-app bot deleted the mny-332 branch December 12, 2025 18:05
@vercel vercel bot temporarily deployed to Production – wallet-ui December 12, 2025 18:05 Inactive
@vercel vercel bot temporarily deployed to Production – nebula December 12, 2025 18:05 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dashboard Involves changes to the Dashboard.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants